package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("permissions/host")
public @caption("授权商户") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("srv_host") class SrvHost implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
	private @caption("编号") @column("sh_id")    @primary  @notnull  @note("  ") Long shId;// 主键 非空     
	private @caption("商户名称") @column("sh_name")     @notnull  @note("  ") String shName;// 非空     
	private @caption("标识") @column("sh_flag")      @note("  ") String shFlag;//     
	private @caption("负责人") @column("sh_master")     @notnull  @note("  ") String shMaster;// 非空     
	private @caption("公司名称") @column("sh_company")     @notnull  @note("  ") String shCompany;// 非空     
	private @caption("描述") @column("sh_desc")     @notnull  @note("  ") String shDesc;// 非空     
	private @caption("状态") @column("sh_status")     @notnull  @note(" 1:正常 0:无效  ") Short shStatus;// 非空 1:正常 0:无效     
	 
	//默认构造函数
	public SrvHost(){ 
	
	}
	
	//主键构造函数
	public SrvHost(Long id){
		this.shId = id;
	}
	
	/**所有字段构造函数 
	 SrvHost(
	 	Utils.getString("shName")//商户名称 [非空]
	 	,Utils.getString("shFlag")//标识
	 	,Utils.getString("shMaster")//负责人 [非空]
	 	,Utils.getString("shCompany")//公司名称 [非空]
	 	,Utils.getString("shDesc")//描述 [非空]
	 	,Utils.getShort("shStatus")//状态 [非空]
	 )
	**/
	public SrvHost(String shName,String shFlag,String shMaster,String shCompany,String shDesc,Short shStatus){
		this.shName=shName;
		this.shFlag=shFlag;
		this.shMaster=shMaster;
		this.shCompany=shCompany;
		this.shDesc=shDesc;
		this.shStatus=shStatus;
	}
	
	//设置非空字段
	public SrvHost setNotNull(String shName,String shMaster,String shCompany,String shDesc,Short shStatus){
		this.shName=shName;
		this.shMaster=shMaster;
		this.shCompany=shCompany;
		this.shDesc=shDesc;
		this.shStatus=shStatus;
		return this;
	}
	/** 编号 [非空]       **/
	public SrvHost shId(Long shId){
		this.shId = shId;
		this.setSeted(F.shId);
		return this;
	}
	/** 商户名称 [非空]       **/
	public SrvHost shName(String shName){
		this.shName = shName;
		this.setSeted(F.shName);
		return this;
	}
	/** 标识        **/
	public SrvHost shFlag(String shFlag){
		this.shFlag = shFlag;
		this.setSeted(F.shFlag);
		return this;
	}
	/** 负责人 [非空]       **/
	public SrvHost shMaster(String shMaster){
		this.shMaster = shMaster;
		this.setSeted(F.shMaster);
		return this;
	}
	/** 公司名称 [非空]       **/
	public SrvHost shCompany(String shCompany){
		this.shCompany = shCompany;
		this.setSeted(F.shCompany);
		return this;
	}
	/** 描述 [非空]       **/
	public SrvHost shDesc(String shDesc){
		this.shDesc = shDesc;
		this.setSeted(F.shDesc);
		return this;
	}
	/** 状态 [非空]   1:正常 0:无效     **/
	public SrvHost shStatus(Short shStatus){
		this.shStatus = shStatus;
		this.setSeted(F.shStatus);
		return this;
	}
	
	
	/**
	* 克隆对象
	**/
	public SrvHost clone(){
		SrvHost clone = new SrvHost();
		clone.shName=this.shName;
		clone.shFlag=this.shFlag;
		clone.shMaster=this.shMaster;
		clone.shCompany=this.shCompany;
		clone.shDesc=this.shDesc;
		clone.shStatus=this.shStatus;
		return clone;
	}
	/**
	* 清除缓存
	**/
	public void clear(){
		Cache.clearObject(SrvHost.M.class);
		Cache.clearValue(SrvHost.M.class);
		Cache.deleteObject(SrvHost.class, this.getId());
	}
	
	/**
	* 清除缓存
	**/
	public static void clear(Long id){
		Cache.clearObject(SrvHost.M.class);
		Cache.clearValue(SrvHost.M.class);
		Cache.deleteObject(SrvHost.class, id);
	}
	
	
	/**
	 * 根据ID取授权商户
	 * @param id
	 * @return
	 */
	public static @api SrvHost get(Long id){		
		return getSrvHostById(id);
	}
	/**
	 * 设置ID
	 * @param id
	 * @return
	 */
	public void setId(Long id){		
		this.shId = id;
	}
	
	/**
	 * 获取所有授权商户
	 * @return
	 */
	public static @api List<SrvHost> list(Map params,Integer size){
		return getSrvHostList(params,size);
	}
	/**
	 * 获取授权商户分页
	 * @return
	 */
	public static @api Page<SrvHost> page(Integer page,Integer size,Map params){
		return getSrvHostPage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取授权商户
	 * @param params
	 * @return
	 */
	public static @api SrvHost Get(Map params){
		return getSrvHost(params);
	}
	/**
	 * 获取授权商户数
	 * @return
	 */
	public static @api Long count(Map params){
		return getSrvHostCount(params);
	}
	/**
	 * 获取授权商户数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getSrvHostEval(eval,params);
	}
	/**
	 * 获取授权商户图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getSrvHostStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取授权商户图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getSrvHostStats(params,sumKey,groupKey,dateType);
	}
	
	/**
	 * 根据ID取授权商户
	 * @param id
	 * @return
	 */
	public static @api SrvHost getSrvHostById(Long id){		
		return getSrvHostDao().getSrvHostById(id);
	}
	/**
	 * 获取id
	 * @return
	 */
	public Long getId(){
		return this.shId;
	}
	
	
	/**
	 * 根据ID取授权商户的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			return null;
		}
		String value = null;
		value = Cache.getValue(SrvHost.class, id);
		if(value==null){
			SrvHost srvHost = get(id);
			if(srvHost!=null){
				String strValue = srvHost.getShName$();
				if(!"ShName".equals("ShName"))
					strValue+="("+srvHost.getShName$()+")";
				Cache.setValue(SrvHost.class, id ,strValue);
				value = strValue;
			}else{
				Cache.setValue(SrvHost.class, id ,"{"+id+"}",30);
				value = "{"+id+"}";
			}
		}
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getShName$();
		if(!"ShName".equals("ShName"))
			keyValue+="("+this.getShName$()+")";
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询授权商户对象
	 * @return
	 */
	public static @api SrvHost find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("shId", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			strDefinex+=" or sh_name = '"+key.replaceAll("'", "''")+"'";
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return SrvHost.getSrvHost(params);
	}
	
	
	/**
	 * 根据关键字查询授权商户
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","sh_id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("shId", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				strDefinex+=" or sh_name like '%"+strTerm.replaceAll("'", "''")+"%'";
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<SrvHost> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(SrvHost srvHost:list){
			Map map = new HashMap();
			map.put("key",srvHost.getShId().toString());
			map.put("value", Utils.js(srvHost.getKeyValue()));
			if(bObject==true)
				map.put("object",srvHost);
			result.add(map);
		}
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有授权商户
	 * @return
	 */
	public static @api List<SrvHost> getSrvHostList(Map params,Integer size){
		return getSrvHostDao().getSrvHostList(params,0,size);
	}
	
	/**
	 * 获取授权商户分页
	 * @return
	 */
	public static @api Page<SrvHost> getSrvHostPage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getSrvHostDao().getSrvHostPage(page, size , params);
	}
	
	/**
	 * 根据查询条件取授权商户
	 * @param params
	 * @return
	 */
	public static @api SrvHost getSrvHost(Map params){
		return getSrvHostDao().getSrvHost(params);
	}
	
	/**
	 * 保存一个授权商户
	 * @param srvHost
	 * @return
	 */
	public static @api SrvHost saveSrvHost(SrvHost srvHost){
		return getSrvHostDao().saveSrvHost(srvHost);
	}
	
	/**
	 * 根据条件更新授权商户
	 * @param values
	 * @param params
	 */
	public static @api int updateSrvHostByConfirm(Map values, Map params){
		return getSrvHostDao().updateSrvHostByConfirm(values,params);
	}
	
	/**
	 * 修改一个授权商户
	 * @param srvHost
	 * @return
	 */
	public static @api int updateSrvHost(SrvHost srvHost){
		return getSrvHostDao().updateSrvHost(srvHost);
	}
	
	/**
	 * 更新授权商户非空字段
	 * @param srvHost
	 */
	public static @api int updateSrvHost$NotNull(SrvHost srvHost){
		return getSrvHostDao().updateSrvHost$NotNull(srvHost);
	}
	
	/**
	 * 获取授权商户数
	 * @return
	 */
	public static @api Long getSrvHostCount(Map params){
		return getSrvHostDao().getSrvHostCount(params);
	}
		
		
	/**
	 * 获取授权商户自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getSrvHostEval(String eval,Map params){
		return getSrvHostDao().getSrvHostEval(eval,params);
	}
	/**
	 * 获取授权商户图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getSrvHostStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getSrvHostDao().getSrvHostStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = SrvHost.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(SrvHost.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateSrvHost(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getSrvHostDao().updateSrvHostByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteSrvHost(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getSrvHostDao().deleteSrvHostByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		getSrvHostDao().removeSrvHostById(id);
	}
	
	
	/**
	 * 保存授权商户对象
	 * @param params
	 * @return
	 */
	public SrvHost save(){
		if(this.getShId()!=null)
			getSrvHostDao().updateSrvHost(this);
		else
			return getSrvHostDao().saveSrvHost(this);
		return this;
	}
	
	
	/**
	 * 更新授权商户对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getSrvHostDao().updateSrvHost$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
		if(Utils.equals(Utils.config("logic_delete"),"true"))
			getSrvHostDao().removeSrvHostById(this.getShId());
		else
			getSrvHostDao().deleteSrvHostById(this.getShId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getSrvHostDao().executeTransaction(function);
	}
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getShId(){
		if(this.shId!=null){
			return this.shId;
		}
		return this.shId;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getShId$(){
		String strValue="";
		 strValue=Utils.string(this.getShId());
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setShId$(String strValue){
		if(Utils.empty(strValue)){
			this.shId=null;
			return;
		}
	 	this.shId=Utils.parseLong(strValue);
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setShId(Long shId){
		this.shId = shId;
		this.setSeted(F.shId);
	}
	
	
	
	
	/*******************************商户名称**********************************/	
	/**
	* 商户名称 [非空]      
	**/
	public String getShName(){
		if(this.shName!=null){
			return this.shName;
		}
		return this.shName;
	}
	/**
	* 获取商户名称格式化(toString)
	**/
	public String getShName$(){
		String strValue="";
		 strValue=Utils.string(this.getShName());
	 	 return strValue;
	}
	/**
	* 根据商户名称反格式化
	**/
	public void setShName$(String strValue){
		if(Utils.empty(strValue)){
			this.shName=null;
			return;
		}
	 	this.shName=strValue;
	}
	
	/**
	* 商户名称 [非空]      
	**/
	public void setShName(String shName){
		this.shName = shName;
		this.setSeted(F.shName);
	}
	
	
	
	
	/*******************************标识**********************************/	
	/**
	* 标识       
	**/
	public String getShFlag(){
		if(this.shFlag!=null){
			return this.shFlag;
		}
		return this.shFlag;
	}
	/**
	* 获取标识格式化(toString)
	**/
	public String getShFlag$(){
		String strValue="";
		 strValue=Utils.string(this.getShFlag());
	 	 return strValue;
	}
	/**
	* 根据标识反格式化
	**/
	public void setShFlag$(String strValue){
		if(Utils.empty(strValue)){
			this.shFlag=null;
			return;
		}
	 	this.shFlag=strValue;
	}
	
	/**
	* 标识       
	**/
	public void setShFlag(String shFlag){
		this.shFlag = shFlag;
		this.setSeted(F.shFlag);
	}
	
	
	
	
	/*******************************负责人**********************************/	
	/**
	* 负责人 [非空]      
	**/
	public String getShMaster(){
		if(this.shMaster!=null){
			return this.shMaster;
		}
		return this.shMaster;
	}
	/**
	* 获取负责人格式化(toString)
	**/
	public String getShMaster$(){
		String strValue="";
		 strValue=Utils.string(this.getShMaster());
	 	 return strValue;
	}
	/**
	* 根据负责人反格式化
	**/
	public void setShMaster$(String strValue){
		if(Utils.empty(strValue)){
			this.shMaster=null;
			return;
		}
	 	this.shMaster=strValue;
	}
	
	/**
	* 负责人 [非空]      
	**/
	public void setShMaster(String shMaster){
		this.shMaster = shMaster;
		this.setSeted(F.shMaster);
	}
	
	
	
	
	/*******************************公司名称**********************************/	
	/**
	* 公司名称 [非空]      
	**/
	public String getShCompany(){
		if(this.shCompany!=null){
			return this.shCompany;
		}
		return this.shCompany;
	}
	/**
	* 获取公司名称格式化(toString)
	**/
	public String getShCompany$(){
		String strValue="";
		 strValue=Utils.string(this.getShCompany());
	 	 return strValue;
	}
	/**
	* 根据公司名称反格式化
	**/
	public void setShCompany$(String strValue){
		if(Utils.empty(strValue)){
			this.shCompany=null;
			return;
		}
	 	this.shCompany=strValue;
	}
	
	/**
	* 公司名称 [非空]      
	**/
	public void setShCompany(String shCompany){
		this.shCompany = shCompany;
		this.setSeted(F.shCompany);
	}
	
	
	
	
	/*******************************描述**********************************/	
	/**
	* 描述 [非空]      
	**/
	public String getShDesc(){
		if(this.shDesc!=null){
			return this.shDesc;
		}
		return this.shDesc;
	}
	/**
	* 获取描述格式化(toString)
	**/
	public String getShDesc$(){
		String strValue="";
		 strValue=Utils.string(this.getShDesc());
	 	 return strValue;
	}
	/**
	* 根据描述反格式化
	**/
	public void setShDesc$(String strValue){
		if(Utils.empty(strValue)){
			this.shDesc=null;
			return;
		}
	 	this.shDesc=strValue;
	}
	
	/**
	* 描述 [非空]      
	**/
	public void setShDesc(String shDesc){
		this.shDesc = shDesc;
		this.setSeted(F.shDesc);
	}
	
	
	
	
	/*******************************状态**********************************/	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public Short getShStatus(){
		if(this.shStatus!=null){
			return this.shStatus;
		}
		return this.shStatus;
	}
	/**
	* 获取状态格式化(toString)
	**/
	public String getShStatus$(){
		String strValue="";
		 if(Utils.equals(Utils.string(this.getShStatus()),"1"))
			strValue=Utils.string("正常");		 
		 if(Utils.equals(Utils.string(this.getShStatus()),"0"))
			strValue=Utils.string("无效");		 
	 	 return strValue;
	}
	/**
	* 根据状态反格式化
	**/
	public void setShStatus$(String strValue){
		if(Utils.empty(strValue)){
			this.shStatus=null;
			return;
		}
		 if(Utils.equals(strValue,"正常"))
		 	this.shStatus=Utils.parseShort("1");
		 if(Utils.equals(strValue,"无效"))
		 	this.shStatus=Utils.parseShort("0");
	}
	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public void setShStatus(Short shStatus){
		this.shStatus = shStatus;
		this.setSeted(F.shStatus);
	}
	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(SrvHost.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(SrvHost.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(SrvHost.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(SrvHost.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(SrvHost.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${SrvHost.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvHost.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvHost.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(SrvHost.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${SrvHost.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvHost.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvHost.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(SrvHost.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		/** 编号 [非空]       **/
		public M shId(Object shId){if(proxy)return proxy().shId(shId);  this.put("shId", shId);return this;};
	 	/** and sh_id is null */
 		public M shIdNull(){if(proxy)return proxy().shIdNull();if(this.get("shIdNot")==null)this.put("shIdNot", "");this.put("shId", null);return this;};
 		/** not .... */
 		public M shIdNot(){if(proxy)return proxy().shIdNot();this.put("shIdNot", "not");return this;};
 		public M shIdNotNull(){if(proxy)return proxy().shIdNotNull();this.put("shIdNot", "not");this.put("shId", null);return this;};
 		public M shIdNot(Object shId){if(proxy)return proxy().shIdNot(shId);this.put("shIdNot", "not");this.put("shId", shId);return this;};
		/** and sh_id <= ? */
		public M shIdMin(Object min){if(proxy)return proxy().shIdMin(min);this.put("shIdMin", min);return this;};
		/** and sh_id >= ? */
		public M shIdMax(Object max){if(proxy)return proxy().shIdMax(max);this.put("shIdMax", max);return this;};
		public M shIdIn(String ids){
			if(proxy)return proxy().shIdIn(ids);  this.put("shIdIn", ids);return this;
		};	
		/** 商户名称 [非空]       **/
		public M shName(Object shName){if(proxy)return proxy().shName(shName);  this.put("shName", shName);return this;};
	 	/** and sh_name is null */
 		public M shNameNull(){if(proxy)return proxy().shNameNull();if(this.get("shNameNot")==null)this.put("shNameNot", "");this.put("shName", null);return this;};
 		/** not .... */
 		public M shNameNot(){if(proxy)return proxy().shNameNot();this.put("shNameNot", "not");return this;};
 		public M shNameNotNull(){if(proxy)return proxy().shNameNotNull();this.put("shNameNot", "not");this.put("shName", null);return this;};
 		public M shNameNot(Object shName){if(proxy)return proxy().shNameNot(shName);this.put("shNameNot", "not");this.put("shName", shName);return this;};
		/** 标识        **/
		public M shFlag(Object shFlag){if(proxy)return proxy().shFlag(shFlag);  this.put("shFlag", shFlag);return this;};
	 	/** and sh_flag is null */
 		public M shFlagNull(){if(proxy)return proxy().shFlagNull();if(this.get("shFlagNot")==null)this.put("shFlagNot", "");this.put("shFlag", null);return this;};
 		/** not .... */
 		public M shFlagNot(){if(proxy)return proxy().shFlagNot();this.put("shFlagNot", "not");return this;};
 		public M shFlagNotNull(){if(proxy)return proxy().shFlagNotNull();this.put("shFlagNot", "not");this.put("shFlag", null);return this;};
 		public M shFlagNot(Object shFlag){if(proxy)return proxy().shFlagNot(shFlag);this.put("shFlagNot", "not");this.put("shFlag", shFlag);return this;};
		/** 负责人 [非空]       **/
		public M shMaster(Object shMaster){if(proxy)return proxy().shMaster(shMaster);  this.put("shMaster", shMaster);return this;};
	 	/** and sh_master is null */
 		public M shMasterNull(){if(proxy)return proxy().shMasterNull();if(this.get("shMasterNot")==null)this.put("shMasterNot", "");this.put("shMaster", null);return this;};
 		/** not .... */
 		public M shMasterNot(){if(proxy)return proxy().shMasterNot();this.put("shMasterNot", "not");return this;};
 		public M shMasterNotNull(){if(proxy)return proxy().shMasterNotNull();this.put("shMasterNot", "not");this.put("shMaster", null);return this;};
 		public M shMasterNot(Object shMaster){if(proxy)return proxy().shMasterNot(shMaster);this.put("shMasterNot", "not");this.put("shMaster", shMaster);return this;};
		/** 公司名称 [非空]       **/
		public M shCompany(Object shCompany){if(proxy)return proxy().shCompany(shCompany);  this.put("shCompany", shCompany);return this;};
	 	/** and sh_company is null */
 		public M shCompanyNull(){if(proxy)return proxy().shCompanyNull();if(this.get("shCompanyNot")==null)this.put("shCompanyNot", "");this.put("shCompany", null);return this;};
 		/** not .... */
 		public M shCompanyNot(){if(proxy)return proxy().shCompanyNot();this.put("shCompanyNot", "not");return this;};
 		public M shCompanyNotNull(){if(proxy)return proxy().shCompanyNotNull();this.put("shCompanyNot", "not");this.put("shCompany", null);return this;};
 		public M shCompanyNot(Object shCompany){if(proxy)return proxy().shCompanyNot(shCompany);this.put("shCompanyNot", "not");this.put("shCompany", shCompany);return this;};
		/** 描述 [非空]       **/
		public M shDesc(Object shDesc){if(proxy)return proxy().shDesc(shDesc);  this.put("shDesc", shDesc);return this;};
	 	/** and sh_desc is null */
 		public M shDescNull(){if(proxy)return proxy().shDescNull();if(this.get("shDescNot")==null)this.put("shDescNot", "");this.put("shDesc", null);return this;};
 		/** not .... */
 		public M shDescNot(){if(proxy)return proxy().shDescNot();this.put("shDescNot", "not");return this;};
 		public M shDescNotNull(){if(proxy)return proxy().shDescNotNull();this.put("shDescNot", "not");this.put("shDesc", null);return this;};
 		public M shDescNot(Object shDesc){if(proxy)return proxy().shDescNot(shDesc);this.put("shDescNot", "not");this.put("shDesc", shDesc);return this;};
		/** 状态 [非空]   1:正常 0:无效     **/
		public M shStatus(Object shStatus){if(proxy)return proxy().shStatus(shStatus);  this.put("shStatus", shStatus);return this;};
	 	/** and sh_status is null */
 		public M shStatusNull(){if(proxy)return proxy().shStatusNull();if(this.get("shStatusNot")==null)this.put("shStatusNot", "");this.put("shStatus", null);return this;};
 		/** not .... */
 		public M shStatusNot(){if(proxy)return proxy().shStatusNot();this.put("shStatusNot", "not");return this;};
 		public M shStatusNotNull(){if(proxy)return proxy().shStatusNotNull();this.put("shStatusNot", "not");this.put("shStatus", null);return this;};
 		public M shStatusNot(Object shStatus){if(proxy)return proxy().shStatusNot(shStatus);this.put("shStatusNot", "not");this.put("shStatus", shStatus);return this;};
		public M shStatusIn(String ids){
			if(proxy)return proxy().shStatusIn(ids);  this.put("shStatusIn", ids);return this;
		};	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	/** 获取所有授权商户 **/
		public @api List<SrvHost> list(Integer size){			
			return getSrvHostList(this,size);
		}
		/** 获取授权商户分页 **/
		public @api Page<SrvHost> page(Integer page,Integer size){			
			return getSrvHostPage(page, size , this);
		}
		/** 根据查询条件取授权商户 **/
		public @api SrvHost get(){			
			return getSrvHost(this);
		}
		/** 获取授权商户数 **/
		public @api Long count(){			
			return getSrvHostCount(this);
		}
		/** 获取授权商户表达式 **/
		public @api <T> T eval(String strEval){			
			return getSrvHostEval(strEval,this);
		}
		/** 获取授权商户统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getSrvHostStats(this,sumKey,groupKey,dateType);
		}
		/** 获取授权商户统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getSrvHostStats(this,sumKey,groupKey,-1);
		}
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateSrvHost(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteSrvHost(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String shId="shId";
		/** 商户名称 [非空]       **/
		public final static @type(String.class)  String shName="shName";
		/** 标识        **/
		public final static @type(String.class)  String shFlag="shFlag";
		/** 负责人 [非空]       **/
		public final static @type(String.class)  String shMaster="shMaster";
		/** 公司名称 [非空]       **/
		public final static @type(String.class)  String shCompany="shCompany";
		/** 描述 [非空]       **/
		public final static @type(String.class)  String shDesc="shDesc";
		/** 状态 [非空]   1:正常 0:无效     **/
		public final static @type(Short.class)  String shStatus="shStatus";
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	/** 对象的数据库字段描述 **/
	public static enum C{
		shId("sh_id"),
		shName("sh_name"),
		shFlag("sh_flag"),
		shMaster("sh_master"),
		shCompany("sh_company"),
		shDesc("sh_desc"),
		shStatus("sh_status"),
		count("count");
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/**
	* 获取授权商户数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = SrvHost.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = SrvHost.getSrvHost(params);
			else
				value = SrvHost.getSrvHostList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  SrvHost.where().shId(param).get();
		else if(!Utils.empty(param.toString()))
			value = SrvHost.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		Map map = new HashMap();
		map.put("id",this.getShId());
		Utils.fms(map,simple?"id":"shId",this.getShId(),this.getShId$());
		Utils.fms(map,simple?"name":"shName",this.getShName(),this.getShName$());
		Utils.fms(map,simple?"flag":"shFlag",this.getShFlag(),this.getShFlag$());
		Utils.fms(map,simple?"master":"shMaster",this.getShMaster(),this.getShMaster$());
		Utils.fms(map,simple?"company":"shCompany",this.getShCompany(),this.getShCompany$());
		Utils.fms(map,simple?"desc":"shDesc",this.getShDesc(),this.getShDesc$());
		Utils.fms(map,simple?"status":"shStatus",this.getShStatus(),this.getShStatus$());
		if(this.suffix!=null)map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
		map.put("shId",this.getShId());
		map.put("shName",this.getShName());
		map.put("shFlag",this.getShFlag());
		map.put("shMaster",this.getShMaster());
		map.put("shCompany",this.getShCompany());
		map.put("shDesc",this.getShDesc());
		map.put("shStatus",this.getShStatus());
		map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static SrvHost fromMap(Map map){
		SrvHost srvHost = new SrvHost();
		srvHost.shId = Utils.parseLong(map.get("shId"));
		srvHost.shName = Utils.parseString(map.get("shName"));
		srvHost.shFlag = Utils.parseString(map.get("shFlag"));
		srvHost.shMaster = Utils.parseString(map.get("shMaster"));
		srvHost.shCompany = Utils.parseString(map.get("shCompany"));
		srvHost.shDesc = Utils.parseString(map.get("shDesc"));
		srvHost.shStatus = Utils.parseShort(map.get("shStatus"));
		return srvHost;
	}
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(SrvHost old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	public static String getIcon(){
		return "/images/icons/20088256423826577805.png";
	}
	public static String getIconfont(){
		return "icon-yunyingfenxi";
	}
	public static enum ACT{
		列表,添加,修改,详情
	};
	public static String getUrl(ACT act,SrvHost.M params){
		if(params==null)params=new SrvHost.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/permissions/host.edit.html?";
		if(params.get("shId")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("shId"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/permissions/host.html?1=1";
		}else if(act==ACT.添加){
			strUrl+="&edittype=insert";
		}else if(act==ACT.修改){
			strUrl+="&edittype=update";
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.shId(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(SrvHost.ACT act,SrvHost.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",SrvHost.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(SrvHost.ACT act,SrvHost.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",SrvHost.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.ISrvHostDao getSrvHostDao(){
		return Utils.getBean("srvHostDao");
	};
	
}